package 算法.base;

import java.util.Arrays;

/**
 * @author lchenglong
 * @date 2022/3/30
 */
public class HashMapTest {


    public static void main(String[] args) {
        fun(3);
    }

    public static void fun(int n){
        String[] dataList = new String[n];
        for (int i=1;i<=n;i++) {
            dataList[i-1] = "" +i;
        }
        arrangementSelect(dataList,new String[n],0);
    }

    private static void arrangementSelect(String[] dataList, String[] resultList, int resultIndex) {
        int resultLen = resultList.length;
        if (resultIndex >= resultLen) { // 全部选择完时，输出排列结果
            System.out.println(Arrays.asList(resultList));
            return;
        }

        // 递归选择下一个
        for (int i = 0; i < dataList.length; i++) {
            // 判断待选项是否存在于排列结果中
            boolean exists = false;
            for (int j = 0; j < resultIndex; j++) {
                if (dataList[i].equals(resultList[j])) {
                    exists = true;
                    break;
                }
            }
            if (!exists) { // 排列结果不存在该项，才可选择
                resultList[resultIndex] = dataList[i];
                arrangementSelect(dataList, resultList, resultIndex + 1);
            }
        }
    }


}
